package com.performax.service;

import java.util.Hashtable;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;


import com.performax.database.Vo.*;
import com.performax.database.Dao.*;


@Controller
@RequestMapping("/app/api/ad")
public class OheGameBannerController {
	private static final Logger logger = LoggerFactory.getLogger(OheGameBannerController.class);
	
	@Resource(name = "oh2gameAdDao")
	private Oh2GameAdDao oh2gameAdDao;
	
	@RequestMapping(value="/rolling")
	@ResponseBody
	public Object rolling(@RequestParam(value="authKey", required=true) 				String authKey
							,@RequestParam(value="mediaCd", defaultValue="mcdoheapp")	String mediaCd
							,@RequestParam(value="userId", required=true) 				String userId
							,@RequestParam(value="gid", defaultValue="XXXXXXXXXX") 		String gid
							,HttpServletRequest req )
	{
		Hashtable<String, Object> result	=	new	Hashtable<String, Object>();
		result.put("resType","rolling");
		result.put("result","1000");
		
		List<RollingInfoVo> bannerList	=	oh2gameAdDao.getRollingBanner();
		
		result.put("rollingInfo",bannerList);
		
		Hashtable<String, String> param	=	new	Hashtable<String, String>();
		
		param.put("authKey", authKey);
		param.put("mediaCd", mediaCd);
		param.put("userId", userId);
		param.put("gid", 	gid);
				
		result.put("resultMessage", param);
		return result;
	}
	
	@RequestMapping(value="/exitpopup")
	@ResponseBody
	public Object exitpopup(@RequestParam(value="authKey", required=true) 				String authKey
							,@RequestParam(value="mediaCd", defaultValue="mcdoheapp")	String mediaCd
							,@RequestParam(value="userId", required=true) 				String userId
							,@RequestParam(value="gid", defaultValue="XXXXXXXXXX") 		String gid
							,HttpServletRequest req )
	{
		
		Hashtable<String, Object> result	=	new	Hashtable<String, Object>();
		result.put("resType","exitpopup");
		result.put("result","1000");
		
		PopupInfoVo popupInfo	=	oh2gameAdDao.getPopupInfo("E");
		
		if(popupInfo	!=	null){
			result.put("bannerUrl",	popupInfo.getBannerUrl());
			String landingType	=	popupInfo.getLandingType();
			result.put("landingType",landingType);
			
			if(landingType.equals("E")){
				result.put("landingAtt",popupInfo.getEventId());
			}else{
				result.put("landingAtt",popupInfo.getLandingUrl());
			}
			
		}
		
		Hashtable<String, String> param	=	new	Hashtable<String, String>();
		
		param.put("authKey", authKey);
		param.put("mediaCd", mediaCd);
		param.put("userId", userId);
		param.put("gid", 	gid);
				
		result.put("resultMessage", param);
		return result;
	}
	
}

